StupidBeauty
Read times:1658Posted at:Fri Dec 20 21:30:01 2013
- no title specified

转载:Defining a percentage width for a LinearLayout?

安卓开发的界面设计过程中,如果想要让一个布局器中各个元素按照比例来占用空间的话,就将各个元素在相应方向上的尺寸设置为0,然后按照比例设置它们的 layout_weight 属性值。

http://stackoverflow.com/questions/6557220/defining-a-percentage-width-for-a-linearlayout

亮点

Hope this can help

<LinearLayout android:layout_width="fill_parent"

android:layout_height="fill_parent" android:orientation="horizontal">

<LinearLayout android:layout_width="0dip"

android:layout_height="wrap_content" android:orientation="horizontal"

android:id="@+id/linearLayout_dummy1" android:layout_weight=".15">

</LinearLayout>

<LinearLayout android:layout_height="wrap_content"

android:id="@+id/linearLayout1" android:orientation="vertical"

android:layout_width="0dip" android:layout_weight=".7">

<Button android:text="Button" android:id="@+id/button1"

android:layout_width="wrap_content" android:layout_height="wrap_content"

android:layout_gravity="center">

</Button>

<Button android:layout_width="wrap_content" android:id="@+id/button2"

android:layout_height="wrap_content" android:text="Button"

android:layout_gravity="center"></Button>

<Button android:layout_width="wrap_content" android:id="@+id/button3"

android:layout_height="wrap_content" android:text="Button"

android:layout_gravity="center"></Button>

</LinearLayout>

<LinearLayout android:layout_width="0dip"

android:layout_height="wrap_content" android:orientation="horizontal"

android:id="@+id/linearLayout_dummy2" android:layout_weight=".15">

</LinearLayout>

</LinearLayout>

(1) Set layout_width to "0dip" (2) Set the layout_height to .xx (% you want)

Mikie Hara

Your opinions
Your name:Email:Website url:Opinion content:
- no title specified

HxLauncher: Launch Android applications by voice commands